// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import com.nokia.symbian 1.1
import com.nokia.extras 1.1

Page {
    id: root
    tools: ToolBarLayout {
        ToolButton {
            iconSource: "toolbar-back"
            onClicked: pageStack.pop();
        }
    }

    InfoAnimadoBackground {
        id: info
        textoInfo: qsTr("_detalhe_header")
        textoDescricao: qsTr("_detalhe_header_desc")
    }

    ListView {
        id: lstMain
        anchors { left: parent.left; top: info.bottom; right: parent.right; bottom: parent.bottom; }
        model: detalheModel
        clip: true
        delegate: Item {
            width: parent.width; height: childrenRect.height

            Rectangle {
                anchors.fill: parent
                color: (index % 2 === 0 ? "#3e0f0f" : platformStyle.colorNormalDark)
            }

            Image {
                id: imgBandeira
                source: (index === (lstMain.count-1) || entregue ? "qrc:///ponto" : "qrc:///bandeira")
                anchors { horizontalCenter: parent.horizontalCenter }
            }

            Image {
                id: imgPlus
                width: 16; height: 16
                source: "qrc:///plus"
                x: imgBandeira.x + imgBandeira.width - 10
                y: imgBandeira.y + 10
                visible: complementos.length > 0
            }

            Column {
                width: childrenRect.width
                anchors { horizontalCenter: parent.horizontalCenter; top: imgBandeira.bottom }

                Row {
                    id: rw
                    spacing: 8

                    Text {
                        text: Qt.formatDateTime(date, qsTr("dd/MM/yyyy hh:mm"))
                        color: platformStyle.colorNormalLight
                        font { pixelSize: 14 }
                    }

                    Text {
                        text: status
                        color: platformStyle.colorNormalLight
                        font { pixelSize: 14; bold: true }
                    }
                }

                Text {
                    id: txtDescricao
                    text: description
                    color: platformStyle.colorNormalLight
                    font { pixelSize: 15 }
                }
            }

            Dialog {
                id: dlgComplementos

                title: HeaderDialogs {
                    texto: qsTr("_detalhe_header")
                }

                content: Item {
                    width: parent.width; height: 300;

                    MeuToolTip {
                        id: meuTool
                        width: parent.width;
                        maxHeight: parent.height
                        clip: true
                        modelo: complementos
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                }

                onStatusChanged: {
                    if (status == DialogStatus.Open) {
                        meuTool.mostrar();
                    } else if (status == DialogStatus.Closing)
                        meuTool.esconder();
                }

                buttons: Button {
                    text: qsTr("_fechar")
                    anchors.horizontalCenter: parent.horizontalCenter
                    onClicked: dlgComplementos.close();
                }
            }

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    if (complementos.length > 0)
                        dlgComplementos.open();
                }
            }
        }
    }
}
